package wzc.design_pattern.behaviour.memento;

/**
 * @Author 那和不是个啥
 * @Date 2025/7/20
 * @Description
 */

public class MementoPatternDemo {
    public static void main(String[] args) {
        TextEditor textEditor = new TextEditor();
        TextEditorHistory history = new TextEditorHistory();

        textEditor.setText("Hello world!!");
        System.out.println("当前文本" + textEditor.getText());
        history.saveMemento(textEditor.save());

        textEditor.setText("Hello java!!");
        System.out.println("当前文本" + textEditor.getText());

        // 撤销操作，恢复到上一个状态
        textEditor.restore(history.getMemento());
        System.out.println("恢复后的文本: " + textEditor.getText());
    }
}
